﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Ex2_Course : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)//不是回发==第一次加载页面
        {
            BindYear();//调用方法
            BindTerm();
            BindCollage();
            BindTeacher();
        }
    }

    /// <summary>
    /// 自定义方法，向"学年"下拉列表框添加10个列表项：当学年及之前的九个
    /// </summary>

    protected void BindYear()
    {
        ddlYear.Items.Clear();//清空学年下拉列表框中的列表项
        int startYear = DateTime.Now.Year - 10;
        int currentYear = DateTime.Now.Year;
        //向学年下拉列表框添加列表项
        for (int i = startYear; i <= currentYear; i++)
        {
            ddlYear.Items.Add(new ListItem((i - 1).ToString() + "-"+i.ToString()));
        }
        //设置“学年下拉列表框的默认列表项”
        ddlYear.SelectedValue = (currentYear - 1).ToString() + "-" + currentYear.ToString();
    }

    /// <summary>
    /// 自定义方法，向“学期”下拉列表框添加1和2
    /// </summary>
    protected void BindTerm()
    {
        ddlTerm.Items.Clear();
        //向学期下拉列表框添加列表项
        for (int i = 1; i <= 2; i++)
        {
            ddlTerm.Items.Add(i.ToString());
        }
    }

    /// <summary>
    /// 自定义方法，向“学院”下拉列表框添加不同的学院
    /// </summary>
    protected void BindCollage()
    {
        ddlCollage.Items.Clear();
        ddlCollage.Items.Add(new ListItem("计算机学院"));
        ddlCollage.Items.Add(new ListItem("外国语学院"));
        ddlCollage.Items.Add(new ListItem("机电学院"));

    }

    /// <summary>
    /// 自定义方法，向“教师”下拉列表框添加不同的教师的名字
    /// </summary>
    protected void BindTeacher()
    {
        ddlTeacher.Items.Clear();
        switch (ddlCollage.SelectedValue)//根据不同的分院添加不同的教师名字
        {
            case "计算机学院":
                ddlTeacher.Items.Add(new ListItem("曹明"));
                ddlTeacher.Items.Add(new ListItem("魏启明"));
                ddlTeacher.Items.Add(new ListItem("杨振宇"));
                break;
            case "外国语学院":
                ddlTeacher.Items.Add(new ListItem("李磊"));
                ddlTeacher.Items.Add(new ListItem("王菲"));
                break;
            case "机电学院":
                ddlTeacher.Items.Add(new ListItem("孟楠"));
                ddlTeacher.Items.Add(new ListItem("刘艾"));
                break;
        }
    }


    protected void ddlCollage_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindTeacher();
    }
}